import { http } from "@/utils/http";

// 房屋租赁基本信息接口
export interface HouseRentalItem {
  id: number;
  houseId: number;
  houseNum: string;
  ownerId: number;
  ownerName: string;
  ownerPhone: string;
  cellId: number;
  cellName: string;
  address: string;
  price: number;
  status: number;
  type: number;
  remark: string;
}

// 查询房屋租赁列表参数
export interface HouseRentalListParams {
  page: number;
  limit: number;
  name?: string;
}

// 通用响应接口
export interface ApiResponse<T = any> {
  code: number;
  data?: T;
  message: string;
}

// 查询房屋租赁列表返回结果
export interface HouseRentalListResult {
  code: number;
  data?: {
    total: number;
    list: HouseRentalItem[];
    pageNum: number;
    pageSize: number;
    size: number;
    startRow: number;
    endRow: number;
    pages: number;
    prePage: number;
    nextPage: number;
    isFirstPage: boolean;
    isLastPage: boolean;
    hasPreviousPage: boolean;
    hasNextPage: boolean;
    navigatePages: number;
    navigatepageNums: number[];
    navigateFirstPage: number;
    navigateLastPage: number;
  };
  message: string;
}

// 添加房屋租赁参数
export interface AddHouseRentalParams {
  houseId: number;
  ownerId: number;
  cellId: number;
  address: string;
  price: number;
  type: number;
  remark: string;
}

// 删除房屋租赁参数
export interface DeleteHouseRentalParams {
  ids: number[];
}

// 修改房屋租赁参数
export interface UpdateHouseRentalParams {
  id: number;
  price: number;
  type: number;
  remark: string;
}

// 房屋出租参数
export interface RentHouseParams {
  renterId: number;
  id: number;
}

/**
 * 查询房屋租赁列表
 * @param data 查询参数
 * @returns 房屋租赁列表数据
 */
export const getHouseRentalList = (data: HouseRentalListParams) => {
  return http.request<HouseRentalListResult>(
    "post",
    "/spHouseRental/queryList",
    {
      data
    }
  );
};

/**
 * 添加房屋租赁
 * @param data 添加参数
 * @returns 操作结果
 */
export const addHouseRental = (data: AddHouseRentalParams) => {
  return http.request<ApiResponse>("post", "/spHouseRental/add", {
    data
  });
};

/**
 * 删除房屋租赁
 * @param data 删除参数
 * @returns 操作结果
 */
export const deleteHouseRental = (data: DeleteHouseRentalParams) => {
  return http.request<ApiResponse>("post", "/spHouseRental/delete", {
    data
  });
};

/**
 * 修改房屋租赁
 * @param data 修改参数
 * @returns 操作结果
 */
export const updateHouseRental = (data: UpdateHouseRentalParams) => {
  return http.request<ApiResponse>("put", "/spHouseRental/update", {
    data
  });
};

/**
 * 房屋出租
 * @param data 出租参数
 * @returns 操作结果
 */
export const rentHouse = (data: RentHouseParams) => {
  return http.request<ApiResponse>("post", "/spHouseRental/rentHouse", {
    data
  });
};
